import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface IClientUserConfig extends mongoose.Document {
	userId: mongoose.Schema.Types.ObjectId;
	isDarkMode: boolean;
	showFastLink: boolean;
	showDataTime: boolean;
	showRecommend: boolean;
	showLogo: boolean;
	defaultSearchEngine: string;
	createdAt?: string;
	updatedAt?: string;
}

// 客户端用户设置
const ClientUserConfigSchema = new mongoose.Schema<IClientUserConfig>(
	{
		userId: {
			type: mongoose.Schema.Types.ObjectId,
		},
		isDarkMode: {
			type: Boolean,
			default: false,
		},
		showFastLink: {
			type: Boolean,
			default: true,
		},
		showDataTime: {
			type: Boolean,
			default: true,
		},
		showRecommend: {
			type: Boolean,
			default: true,
		},
		showLogo: {
			type: Boolean,
			default: true,
		},
		defaultSearchEngine: {
			type: String,
			default: 'internal',
			enum: ['internal', 'google', 'bing', 'baidu'],
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'client_user_config',
	}
);

export const ClientUserConfigModel = mongoose.model('ClientUserConfig', ClientUserConfigSchema);
